window.onload = function(){
    //$("#loadingMsgBox").css("display","none");

    //check for canvas support
    var canvasEl = document.createElement('canvas'); //create the canvas object
    if(!(canvasEl.getContext && canvasEl.getContext('2d'))){ //if the method is not supported, i.e canvas is not supported
        var msg = "OOPS!! Your browser does not support a feature that is used by our application. Why not try it in a newer browser - IE9+ onwards or the latest versions of Chrome, Safari, Firefox.";
        $("#bodyTag").html("<p class='errorMsg'>" + msg + "</p>");
        return;
    }
    //check for cookies
    if(!(navigator.cookieEnabled)){ // && navigator['cookieEnabled'] != null, this is really not needed
        var msg = "It seems you have disabled cookied in your browser. Cookies must be enabled in your browser for this app to function";
        $("#bodyTag").html("<p class='errorMsg'>" + msg + "</p>");
        return;
    }

    $("#contentLayout").fadeIn(300);
    $("#navigationLinks").fadeIn(500);
}
function showValue(text,value){
        //console.log(text);
    switch(value){
        case "Canada1":
            //window.location.href = "app.html";
            showPopUpMessage("By clicking AGREE - I agree that my HeartCANVAS can be used by HeartPRENEUR Inc. unconditionally for the purpose of raising funds for HeartESTEEM for perpetuity without any restrictions and I forego all copyright rights of my drawing with love for HeartESTEEM.");
            break;
        case "USA":
        //countryLogo = "usa";
            break;
        case "India":
        //countryLogo = "india";
            break;
    }
}

$(function(){
    //alert('hello');
    var modalWindowElement = null, okBtn = null, overlayElement=null;

    //initialize all the user events
    initializeEvents();

    $( "#readyBtn" ).button();

    /* Functions Start*/
    function initializeEvents() {
        $("#readyBtn").click(drawingReady);

        //$("#regionList").change(selectRegion);
    }

    //try {
        $("body select").msDropDown();
    //} catch(e) {
        //alert(e.message);
    //}

    function drawingReady(){
        //only if Canada-En is selected
        var selectedOption = $("#regionList").val();
        if(selectedOption == "Canada1")
            //window.location.href = "app.html";
            showPopUpMessage("By clicking AGREE - I agree that my HeartCANVAS can be used by HeartPRENEUR Inc. unconditionally for the purpose of raising funds for HeartESTEEM for perpetuity without any restrictions and I forego all copyright rights of my drawing with love for HeartESTEEM.");
    }


    /*function selectRegion(){
        console.log($(this).val());
        switch($(this).val()){
            case "Canada1":
                //window.location.href = "app.html";
                showPopUpMessage("By clicking AGREE - I agree that my HeartCANVAS can be used by HeartPRENEUR Inc. unconditionally for the purpose of raising funds for HeartESTEEM for perpetuity without any restrictions and I forego all copyright rights of my drawing with love for HeartESTEEM.");
            break;
            case "USA":
            //countryLogo = "usa";
            break;
            case "India":
            //countryLogo = "india";
            break;
        }
    } */
});

//show the modal overlay and popup window
function showPopUpMessage(msg) {
    overlayElement = document.createElement("div");
    overlayElement.className = 'modalOverlay';
    //console.log($(this).offset().left);

    modalWindowElement = document.createElement("div");
    modalWindowElement.className = 'modalWindow';
    modalWindowElement.innerHTML = "<p style='text-align:justify; word-spacing:0px; line-height:20px; font-weight:normal !important;'>" + msg + "</p>";
    modalWindowElement.style.width = "400px";
    modalWindowElement.style.height = "auto";


    okBtn = document.createElement("div");
    okBtn.className = "redBtn okBtn";
    okBtn.id = "agreeBtn";
    okBtn.innerHTML = "<p>AGREE</p>";
    //okBtn.addEventListener("click",function(){ hidePopUpMessage(); },false);

    modalWindowElement.appendChild(okBtn);
    document.body.appendChild(overlayElement);
    document.body.appendChild(modalWindowElement);
    modalWindowElement.style.left = (window.innerWidth - $(".modalWindow").width()) / 2 + "px";
    modalWindowElement.style.top = (window.innerHeight - $(".modalWindow").height()) / 2 + "px";
    //console.log(window.innerWidth);
    $("#agreeBtn").click(hidePopUpMessage);
}
//hide the modal overlay and popup window
function hidePopUpMessage() {
    document.body.removeChild(overlayElement);
    document.body.removeChild(modalWindowElement);
    window.location.href = "app.php";
}

